/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

namespace DaveSexton.DocProject.DocSites
{
	public struct KeywordEntry : IEquatable<KeywordEntry>, IComparable<KeywordEntry>
	{
		#region Public Properties
		public string Keyword { get { return word; } }

		public int EntryCount
		{
			get
			{
				return entries.Count;
			}
		}

		public ICollection<IndexEntry> Entries
		{
			get
			{
				return new System.Collections.ObjectModel.ReadOnlyCollection<IndexEntry>(entries);
			}
		}
		#endregion

		#region Private / Protected
		private readonly string word;
		private readonly IList<IndexEntry> entries;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="KeywordEntry" /> structure.
		/// </summary>
		public KeywordEntry(string keyword, IEnumerable<IndexEntry> entries)
		{
			this.word = keyword;
			this.entries = new List<IndexEntry>(entries);
		}
		#endregion

		#region Methods
		public override string ToString()
		{
			return word;
		}

		public override bool Equals(object obj)
		{
			if (obj is KeywordEntry)
				return Equals((KeywordEntry) obj);
			else
				return base.Equals(obj);
		}

		public override int GetHashCode()
		{
			return (word ?? "").GetHashCode();
		}

		public static bool operator ==(KeywordEntry entry1, KeywordEntry entry2)
		{
			return entry1.Equals(entry2);
		}

		public static bool operator !=(KeywordEntry entry1, KeywordEntry entry2)
		{
			return !entry1.Equals(entry2);
		}

		public static bool operator <(KeywordEntry entry1, KeywordEntry entry2)
		{
			return entry1.CompareTo(entry2) < 0;
		}

		public static bool operator >(KeywordEntry entry1, KeywordEntry entry2)
		{
			return entry1.CompareTo(entry2) > 0;
		}
		#endregion

		#region IEquatable<KeywordEntry> Members
		public bool Equals(KeywordEntry other)
		{
			return string.Equals(word, other.word, StringComparison.OrdinalIgnoreCase);
		}
		#endregion

		#region IComparable<KeywordEntry> Members
		public int CompareTo(KeywordEntry other)
		{
			return string.Compare(word, other.word, StringComparison.OrdinalIgnoreCase);
		}
		#endregion
	}
}
